<template>
  <div>
    <el-dialog
      v-el-drag-dialog
      :title="title"
      :close-on-click-modal="false"
      v-model="show"
      width="800px"
      append-to-body
      @closed="dialogClosed"
    >
      <el-form
        ref="formRef"
        :model="formData"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="所属参数" required>
          <el-input value="根节点" disabled />
        </el-form-item>
        <el-form-item label="数据格式" required>
          <el-radio-group v-model="formData.importType">
            <el-radio label="JSON"></el-radio>
            <el-radio label="XML"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="参数内容" props="importValue">
          <el-input
            v-model="formData.importValue"
            type="textarea"
            placeholder="请输入参数内容"
            rows="12"
          ></el-input>
        </el-form-item>
      </el-form>
      <dialog-footer @ok="onOk" @cancel="onCancel" />
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: "",
    },
    batchVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      formData: {
        importType: "JSON",
        importValue: "",
      },
      rules: {
        importValue: [
          { required: true, message: "参数内容不可以为空", trigger: "blur" },
        ],
      },
    };
  },
  computed: {
    show: {
      get() {
        return this.batchVisible;
      },
      set(val) {
        this.$emit("update:batchVisible", val);
      },
    },
  },
  methods: {
    onOk() {
      this.$refs["formRef"].validate((v) => {
        if (v) {
          this.$emit("onOk", this.formData);
        }
      });
    },
    onCancel() {
      this.show = false
      this.$emit("update:batchVisible", false);
      this.$emit("onCancel");
    },
    dialogClosed() {
      this.formData = {
        importType: "JSON",
        importValue: "",
      }
    }
  },
};
</script>
